package cn.numeron.common.accident

import cn.numeron.stateful.livedata.StatefulLiveData
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlin.coroutines.CoroutineContext

class CatchExceptionTo(private val statefulLiveData: StatefulLiveData<*>) : CoroutineExceptionHandler {

    override val key: CoroutineContext.Key<*>
        get() = CoroutineExceptionHandler

    override fun handleException(context: CoroutineContext, exception: Throwable) {
        statefulLiveData.postFailure(exception)
    }

}